import { useAppSelector } from "../app/hooks";

export function useCart() {
  // 仓库数据
  const cartList = useAppSelector(state => state.cart.cartList);
  // 全选状态
  const totalState = cartList.every(v => v.state);
  // 总价钱 -- 选中
  const totalPrice = cartList.filter(v => v.state).reduce((p, n) => {
    return p + n.count * n.price
  }, 0)
  // 总数量
  const totalCount = cartList.reduce((p, n) => {
    return p + n.count
  }, 0)

  return {
    totalState,
    totalPrice,
    totalCount
  }
}